// ==UserScript==
// @name         巨量项目批量助手
// @namespace    https://gitee.com/kuiwaiwai
// @version      0.1
// @description  巨量引擎批量助手
// @author       kuiwaiwai
// @match        https://*.oceanengine.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // 创建批量开启项目按钮
    var openProjectButton = document.createElement("button");
    openProjectButton.innerHTML = "批量开启项目";
    openProjectButton.style.position = "fixed";
    openProjectButton.style.top = "40%";
    openProjectButton.style.left = "30%";
    openProjectButton.style.transform = "translate(-50%, -50%)";
    openProjectButton.style.opacity = "0.5";
    openProjectButton.style.background = "blue";
    openProjectButton.style.color = "white";
    openProjectButton.style.border = "none";
    openProjectButton.style.padding = "5px 10px";
    openProjectButton.style.borderRadius = "5px";
    openProjectButton.style.zIndex = "9999";

    // 批量开启项目按钮点击事件
    openProjectButton.addEventListener ("click", function() {
        var interval = setInterval(function() {
            var elements = document.getElementsByClassName('ovui-switch ovui-switch--xs');
            if(elements.length === 0) {
                clearInterval(interval);
            } else {
                for(var i = 0; i < elements.length; i++) {
                    if(!elements[i].classList.contains('ovui-switch--checked')) {
                        elements[i].click();
                    }
                }
            }
        }, 500);
    });

    document.body.appendChild(openProjectButton);

    // 创建批量关闭项目按钮
    var closeProjectButton = document.createElement("button");
    closeProjectButton.innerHTML = "批量关闭项目";
    closeProjectButton.style.position = "fixed";
    closeProjectButton.style.top = "40%";
    closeProjectButton.style.left = "40%";
    closeProjectButton.style.transform = "translate(-50%, -50%)";
    closeProjectButton.style.opacity = "0.5";
    closeProjectButton.style.background = "blue";
    closeProjectButton.style.color = "white";
    closeProjectButton.style.border = "none";
    closeProjectButton.style.padding = "5px 10px";
    closeProjectButton.style.borderRadius = "5px";
    closeProjectButton.style.zIndex = "9999";

    // 批量关闭项目按钮点击事件
    closeProjectButton.addEventListener ("click", function() {
        var interval = setInterval(function() {
            var elements = document.getElementsByClassName('ovui-switch ovui-switch--xs ovui-switch--checked');
            if(elements.length === 0) {
                clearInterval(interval);
            } else {
                for(var i = 0; i < elements.length; i++) {
                    elements[i].click();
                }
            }
        }, 500);
    });

    document.body.appendChild(closeProjectButton);

    // 创建批量开启广告按钮
    var openAdButton = document.createElement("button");
    openAdButton.innerHTML = "批量开启广告";
    openAdButton.style.position = "fixed";
    openAdButton.style.top = "40%";
    openAdButton.style.left = "50%";
    openAdButton.style.transform = "translate(-50%, -50%)";
    openAdButton.style.opacity = "0.5";
    openAdButton.style.background = "blue";
    openAdButton.style.color = "white";
    openAdButton.style.border = "none";
    openAdButton.style.padding = "5px 10px";
    openAdButton.style.borderRadius = "5px";
    openAdButton.style.zIndex = "9999";

    // 批量开启广告按钮点击事件
    openAdButton.addEventListener ("click", function() {
        var interval = setInterval(function() {
            var elements = document.getElementsByClassName('ovui-switch ovui-switch--sm');
            if(elements.length === 0) {
                clearInterval(interval);
            } else {
                for(var i = 0; i < elements.length; i++) {
                    if(!elements[i].classList.contains('ovui-switch--checked')) {
                        elements[i].click();
                    }
                }
            }
        }, 500);
    });

    document.body.appendChild(openAdButton);

    // 创建批量关闭广告按钮
    var closeAdButton = document.createElement("button");
    closeAdButton.innerHTML = "批量关闭广告";
    closeAdButton.style.position = "fixed";
    closeAdButton.style.top = "40%";
    closeAdButton.style.left = "60%";
    closeAdButton.style.transform = "translate(-50%, -50%)";
    closeAdButton.style.opacity = "0.5";
    closeAdButton.style.background = "blue";
    closeAdButton.style.color = "white";
    closeAdButton.style.border = "none";
    closeAdButton.style.padding = "5px 10px";
    closeAdButton.style.borderRadius = "5px";
    closeAdButton.style.zIndex = "9999";

    // 批量关闭广告按钮点击事件
    closeAdButton.addEventListener ("click", function() {
        var interval = setInterval(function() {
            var elements = document.getElementsByClassName('ovui-switch ovui-switch--sm ovui-switch--checked');
            if(elements.length === 0) {
                clearInterval(interval);
            } else {
                for(var i = 0; i < elements.length; i++) {
                    elements[i].click();
                }
            }
        }, 500);
    });

    document.body.appendChild(closeAdButton);
})();
